//
//  SettingsController.swift
//  maopu
//
//  Created by xiongsh on 2017/5/8.
//  Copyright © 2017年 maopu. All rights reserved.
//

import UIKit

class SettingsController: BaseViewController {
    fileprivate var table: UITableView!
    fileprivate var arrayData: NSArray!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.initView()
        self.initData()
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.setNavigationBarHidden(false, animated: true)
    }
    
    func initData() {
        self.arrayData = [[["title":"推送开关"]],[["title":"我的账号"],["title":"清理缓存"]],[["title":"关于我们"],["title":"评个分吧"],["title":"常见问题"],["title":"官方网站"],["title":"官方微博"],["title":"协议与申明"]]]
    }
    
    func initView() {
        self.title = "系统设置"
        self.table = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: AppWidth, height: AppHeight), style: .grouped)
        self.table.delegate = self
        self.table.dataSource = self
        self.table.register(UITableViewCell.self, forCellReuseIdentifier: "SettingsController")
        self.table.rowHeight = 50.0
        self.table.showsVerticalScrollIndicator = false
        self.view.addSubview(self.table)

    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
extension SettingsController: UITableViewDelegate, UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return self.arrayData.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (self.arrayData[section] as! NSArray).count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 1 && indexPath.row == 1 {
            var cell = tableView.dequeueReusableCell(withIdentifier: "SettingsController2")
            if cell == nil {
                cell = UITableViewCell.init(style: .value1, reuseIdentifier: "SettingsController2")
            }
            let valuc: NSDictionary = (self.arrayData[indexPath.section] as! NSArray)[indexPath.row] as! NSDictionary
            cell?.textLabel?.text = valuc.object(forKey: "title") as! String?
            cell?.accessoryType = .none
            cell?.detailTextLabel?.text = "100M"
            return cell!
        }
        else {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SettingsController", for: indexPath)
        let valuc: NSDictionary = (self.arrayData[indexPath.section] as! NSArray)[indexPath.row] as! NSDictionary
        cell.textLabel?.text = valuc.object(forKey: "title") as! String?
        cell.accessoryType = .disclosureIndicator
        return cell
        }
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        if indexPath.section == 0 {
            switch indexPath.row {
            case 0:
                
                break
                
            default:
                
                break
            }
        }
        
        if indexPath.section == 1 {
            switch indexPath.row {
            case 0:
                
                break
                
            case 1:
                
                break
                
            case 2:
                
                break
                
            default:
                
                break
            }
        }
        if indexPath.section == 2 {
            switch indexPath.row {
            case 0:
                let vc = H5ViewController.init(title: "关于我们", url: URL.init(string: "http://help.mop.com/about.jsp")!)
                self.navigationController?.pushViewController(vc, animated: true)
                break
                
            case 1:
                let vc = FeedbackController()
                self.navigationController?.pushViewController(vc, animated: true)
                break
                
            case 2:
                
                break
              
            case 3:
                let vc = H5ViewController.init(title: "官方网址", url: URL.init(string: "http://www.mop.com")!)
                self.navigationController?.pushViewController(vc, animated: true)
                break
            default:
                
                break
            }
        }
        
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 5.0
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }

}
